/**
 * 
 */
package com.hexacta.hrs.repositories.impl;

import java.util.Collection;

import org.hibernate.criterion.Example;
import org.hibernate.criterion.MatchMode;

import com.hexacta.hrs.timeoff.VacationDaysCalculationDetail;

/**
 * Representa un objeto de repositorio para el objeto {@link VacationDaysCalculationDetail}.
 * @author sramusio
 * 
 */
public class VacationDaysCalculationDetailRecordObjectRepository extends HibernateRecordObjectRepository<VacationDaysCalculationDetail> {

	public VacationDaysCalculationDetailRecordObjectRepository(Class<VacationDaysCalculationDetail> entityClass) {
		super(entityClass);
	}

	/** {@inheritDoc} */
	@SuppressWarnings("unchecked")
	@Override
	public Collection<VacationDaysCalculationDetail> matching(VacationDaysCalculationDetail criteria) {
		if (criteria.getCalculatedBy() == null)
			return super.matching(criteria);
		Example exampleVacationDaysCalculationDetail = Example.create(criteria)
				.ignoreCase().enableLike(MatchMode.ANYWHERE);
		Example exampleEmployee = Example.create(criteria.getCalculatedBy())
				.ignoreCase().enableLike(MatchMode.ANYWHERE);
		return getSession().createCriteria(VacationDaysCalculationDetail.class).add(
				exampleVacationDaysCalculationDetail).createCriteria("calculatedBy").add(
				exampleEmployee).list();
	}

}
